import router from "./index"
import { isRuleRouter } from "../util/isRlueRouter"
import { useStore } from "vuex"
import { close, start } from '../util/nprogress'
router.beforeEach((to, from, next) => {
    const token = JSON.parse(sessionStorage.getItem("token")!)

    start()
    // return next()
    //判断是否鉴权页面
    // console.log(to)
    if (to.matched.some(record => record.meta.isRule)) {
        if (token) {
            //登录完成获取用户权限 并且修改 ruleRoter的值  1代表的管理员
            // store.dispatch("ruleStore/changeRuleRouter",isRuleRouter(1))
            sessionStorage.setItem("rule",token.rule)
            next()
        } else {
            next({ path: '/login' })
        }
    } else {
        if (token && to.path == "/login") {
            next({path:"/"})
        }
        
        next()
    }
})

router.afterEach(() => {
    close()
})